import React from 'react'
import { NavigationStackScreenComponent } from 'react-navigation-stack'
import { View, Text, Image, Alert } from 'react-native'
import { InfoLayout, RadiusButton } from 'components'
import { commonStyle } from 'styles'
import { settingStyle } from './styles'
import assets from './assets'
import { TouchableOpacity } from 'react-native-gesture-handler'
import { navigate, navigateReplace } from 'services/navigation';
import { getAuthorization, loginOut } from 'services/authorization';
import { usePayContext } from 'services/PayContext'
import pos from 'api/pos';
import { navigator } from '../services/navigation';

const SettingScreen: NavigationStackScreenComponent = props => {
	const payContext = usePayContext()
	return (
		<View style={[commonStyle.containerColumn, settingStyle.container]}>
			<InfoLayout
				title="当前项目:"
				content={getAuthorization().project.name}
				contentIcon={assets.images.icon_arrow_right}
				onContentPress={() => {
					navigate('ChangeProject')
				}}
			// contentView={
			// 	<RadiusButton style={settingStyle.rightArrow} onPress={() => {
			// 		navigate('ChangeProject')
			// 	}}>
			// 		<View style={settingStyle.rightContent}>
			// 			<Text>{getAuthorization().project.name}</Text>
			// 			<Image source={assets.images.icon_arrow_right} />
			// 		</View>
			// 	</RadiusButton>
			// }
			/>
			< InfoLayout
				title="同步主数据"
				contentView={
					< RadiusButton style={{ ...commonStyle.ringButton, ...settingStyle.btn }} onPress={() => { pos.posApp.syncProject({ mac: getAuthorization().mac, id: getAuthorization().userId }) }}>
						<Text style={settingStyle.btnTitle}>刷新</Text>
					</RadiusButton >
				}
			/>
			< InfoLayout title="绑定打印机:" content="787937297329479" />
			< InfoLayout
				title="同步收款数据"
				contentView={
					< RadiusButton style={{ ...commonStyle.ringButton, ...settingStyle.btn }} onPress={() => { payContext.sendAllData() }}>
						<Text style={settingStyle.btnTitle}>{payContext.allPayData.length > 0 ? '同步' : '已同步'}</Text>
					</RadiusButton >
				}
			/>
			<View style={[commonStyle.loginOutContainer]}>
				<RadiusButton style={commonStyle.loginOutBtn} onPress={() => {
					loginOut()
					props.navigation.popToTop()
					navigateReplace('SignIn')
				}}>
					<Text style={commonStyle.loginOutBtnText}>退出登录</Text>
				</RadiusButton></View>
		</View >
	)
}

SettingScreen.navigationOptions = props => {
	return {
		title: '系统设置',
	}
}

export default SettingScreen
